// pages/ucenter/index/index.js
import Util from '../../../utils/util';
var app = getApp();
let that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text1:'1xx-xxxx-xxx',
    text2:'123456@mail.com',
    userInfo: {},
    isLogin: false,
    show: {
      bottom:false
    }
  },

  toggle(type, show) {
    this.setData({
      [`show.${type}`]: show
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '个人中心'
    })
    that = this;
  },
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    let isLogin = wx.getStorageSync('isLogin');
    // 页面显示
    if (userInfo && isLogin) {
      this.setData({
        userInfo: userInfo,
        isLogin: isLogin
      });
    } else {
      // 未登录信息
      this.setData({
        userInfo: app.globalData.userInfo,
        isLogin: isLogin
      });
    }
    // 动画
    let animation = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease'
    });
    let next = true;
    let count = 0;
    // 连续动画
    setInterval(function () {
      if(count>3){
        return ;
      }
      if (next) {
        animation.translateX(6).step()
        next = !next;
      } else {
        animation.translateX(0).step()
        next = !next;
      }
      this.setData({
        ani: animation.export()
      })
      count++;
    }.bind(this), 800)
  },
  toLogin() {
    if (!this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/auth/toLogin/toLogin',
      })
    }
  },
  checkLogin() {
    if (!this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/auth/toLogin/toLogin',
      })
    }
  },
  toAward() {
    Util.checkLogin();
    wx.navigateTo({
      url: '/pages/user/award/index/index',
    })
  },
  toOrder() {
    Util.checkLogin();
    wx.navigateTo({
      url: '/pages/user/order/index/index',
    })
  },
  toAddress() {
    Util.checkLogin();
    wx.navigateTo({
      url: '/pages/user/address/myaddress/index',
    })
  },


  showBottom() {
    this.toggle('bottom', true);
  },

  hideBottom() {
    this.toggle('bottom', false);
  },


  // toCustomerCare() {
  //   Util.checkLogin();
  //   wx.navigateTo({
  //     url: '/pages/user/customer-care/index/index',
  //   })
  // },
  toAgreement() {
    Util.checkLogin();
    wx.navigateTo({
      url: '/pages/user/agreement/index/index',
    })
  },
})